﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IP.Core.IPData;
using IP.Core.IPUserService;
using BKIDS;
using BKIDS.CDBNames;
using BKIUS;
using IP.Core.IPCommon;
using System.Data;

public partial class DanhMuc_F602_Tien_do_Du_an : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data_2_combo_ten_du_an();
            load_data_2_combo_trang_thai_cv();
            load_data_2_grv();
            load_data_2_cbo_ten_du_an_s();
            load_data_2_cbo_thanh_vien_s();
            load_data_2_combo_trang_thai_da_s();
        }
        load_ten_thanh_vien_by_id_du_an_2_cbo_ten_thanh_vien();
        load_data_2_combo_cong_viec();
    }

    #region Members
    US_GD_CONG_VIEC_THANH_VIEN_TIEN_DO_DU_AN m_us_gd_cong_viec_thanh_vien_tien_do_du_an = new US_GD_CONG_VIEC_THANH_VIEN_TIEN_DO_DU_AN();
    DS_GD_CONG_VIEC_THANH_VIEN_TIEN_DO_DU_AN m_ds_gd_cong_viec_thanh_vien_tien_do_du_an = new DS_GD_CONG_VIEC_THANH_VIEN_TIEN_DO_DU_AN();
    #endregion

    // Cách 2: Viết code để map ID_THANH_VIEN với TEN_THANH_VIEN
    #region Private Methods
    private void load_data_2_combo_ten_du_an()
    {
        US_DM_DU_AN v_us_du_an = new US_DM_DU_AN();
        DS_DM_DU_AN v_ds_du_an = new DS_DM_DU_AN();

        v_us_du_an.FillDataset(v_ds_du_an);

        m_cbo_ten_du_an.DataTextField = DM_DU_AN.TEN_DU_AN;
        m_cbo_ten_du_an.DataValueField = DM_DU_AN.ID;

        m_cbo_ten_du_an.DataSource = v_ds_du_an.DM_DU_AN;
        m_cbo_ten_du_an.DataBind();
    }
    private void load_data_2_combo_cong_viec()
    {
        if (m_cbo_ten_du_an.Text != "")
        {
            m_cbo_cong_viec.Enabled = true;
            US_DM_CONG_VIEC_DU_AN v_us_cong_viec_du_an = new US_DM_CONG_VIEC_DU_AN();
            DS_DM_CONG_VIEC_DU_AN v_ds_cong_viec_du_an = new DS_DM_CONG_VIEC_DU_AN();

            v_us_cong_viec_du_an.FillDataset(v_ds_cong_viec_du_an, " WHERE ID_LOAI_DU_AN= (SELECT ID_LOAI_DU_AN FROM DM_DU_AN WHERE ID =" + CIPConvert.ToDecimal(m_cbo_ten_du_an.SelectedValue) + ")"); // Load công việc theo loại dự án

            m_cbo_cong_viec.DataTextField = DM_CONG_VIEC_DU_AN.TEN_CONG_VIEC;
            m_cbo_cong_viec.DataValueField = DM_CONG_VIEC_DU_AN.ID;

            m_cbo_cong_viec.DataSource = v_ds_cong_viec_du_an.DM_CONG_VIEC_DU_AN;
            m_cbo_cong_viec.DataBind();
        }
    }
    private void load_ten_thanh_vien_by_id_du_an_2_cbo_ten_thanh_vien()
    {
        US_V_DM_THANH_VIEN v_us_dm_thanh_vien = new US_V_DM_THANH_VIEN();
        DS_V_DM_THANH_VIEN v_ds_dm_thanh_vien = new DS_V_DM_THANH_VIEN();

        v_us_dm_thanh_vien.FillDataset(v_ds_dm_thanh_vien, " WHERE ID IN (SELECT ID_THANH_VIEN FROM DM_THANH_VIEN_DU_AN WHERE ID_DU_AN=" + CIPConvert.ToDecimal(m_cbo_ten_du_an.SelectedValue) + ")");

        m_cbo_ten_thanh_vien.DataTextField = V_DM_THANH_VIEN.TEN_DAY_DU;
        m_cbo_ten_thanh_vien.DataValueField = V_DM_THANH_VIEN.ID;

        m_cbo_ten_thanh_vien.DataSource = v_ds_dm_thanh_vien.V_DM_THANH_VIEN;
        m_cbo_ten_thanh_vien.DataBind();
    }
    private void load_data_2_combo_trang_thai_cv()
    {
        US_CM_DM_TU_DIEN v_us_tu_dien = new US_CM_DM_TU_DIEN();
        DS_CM_DM_TU_DIEN v_ds_tu_dien = new DS_CM_DM_TU_DIEN();

        v_us_tu_dien.FillDataset(v_ds_tu_dien, "WHERE ID_LOAI_TU_DIEN=8");

        m_cbo_trang_thai.DataTextField = CM_DM_TU_DIEN.TEN;
        m_cbo_trang_thai.DataValueField = CM_DM_TU_DIEN.ID;

        m_cbo_trang_thai.DataSource = v_ds_tu_dien.CM_DM_TU_DIEN;
        m_cbo_trang_thai.DataBind();
    }
    private void load_data_2_grv()
    {
        m_us_gd_cong_viec_thanh_vien_tien_do_du_an.FillDataset(m_ds_gd_cong_viec_thanh_vien_tien_do_du_an);
        m_grv_tien_do_du_an.DataSource = m_ds_gd_cong_viec_thanh_vien_tien_do_du_an.GD_CONG_VIEC_THANH_VIEN_TIEN_DO_DU_AN;
        m_grv_tien_do_du_an.DataBind();
    }

    private void load_data_2_cbo_ten_du_an_s()
    {
        US_DM_DU_AN v_us_du_an = new US_DM_DU_AN();
        DS_DM_DU_AN v_ds_du_an = new DS_DM_DU_AN();

        v_us_du_an.FillDataset(v_ds_du_an);

        m_cbo_ten_du_an_s.Items.Add(new ListItem("Tất cả", CIPConvert.ToStr(0)));
        for (int v_i = 0; v_i < v_ds_du_an.DM_DU_AN.Rows.Count; v_i++)
        {
            m_cbo_ten_du_an_s.Items.Add(new ListItem(CIPConvert.ToStr(v_ds_du_an.DM_DU_AN.Rows[v_i][DM_DU_AN.TEN_DU_AN]), CIPConvert.ToStr(v_ds_du_an.DM_DU_AN.Rows[v_i][DM_DU_AN.ID])));
        }
    }
    private void load_data_2_cbo_thanh_vien_s()
    {
        US_V_DM_THANH_VIEN v_us_dm_thanh_vien = new US_V_DM_THANH_VIEN();
        DS_V_DM_THANH_VIEN v_ds_dm_thanh_vien = new DS_V_DM_THANH_VIEN();

        v_us_dm_thanh_vien.FillDataset(v_ds_dm_thanh_vien);

        m_cbo_ten_thanh_vien_s.Items.Add(new ListItem("Tất cả", CIPConvert.ToStr(0)));
        for (int v_i = 0; v_i < v_ds_dm_thanh_vien.V_DM_THANH_VIEN.Rows.Count; v_i++)
        {
            m_cbo_ten_thanh_vien_s.Items.Add(new ListItem(CIPConvert.ToStr(v_ds_dm_thanh_vien.V_DM_THANH_VIEN.Rows[v_i][V_DM_THANH_VIEN.TEN_DAY_DU]), CIPConvert.ToStr(v_ds_dm_thanh_vien.V_DM_THANH_VIEN.Rows[v_i][V_DM_THANH_VIEN.ID])));
        }
    }
    private void load_data_2_combo_trang_thai_da_s()
    {
        US_CM_DM_TU_DIEN v_us_tu_dien = new US_CM_DM_TU_DIEN();
        DS_CM_DM_TU_DIEN v_ds_tu_dien = new DS_CM_DM_TU_DIEN();

        v_us_tu_dien.FillDataset(v_ds_tu_dien, "WHERE ID_LOAI_TU_DIEN=2");
        m_cbo_trang_thai_s.Items.Add(new ListItem("Tất cả", CIPConvert.ToStr(0)));
        for (int v_i = 0; v_i < v_ds_tu_dien.CM_DM_TU_DIEN.Rows.Count; v_i++)
        {
            m_cbo_trang_thai_s.Items.Add(new ListItem(CIPConvert.ToStr(v_ds_tu_dien.CM_DM_TU_DIEN.Rows[v_i][CM_DM_TU_DIEN.TEN]), CIPConvert.ToStr(v_ds_tu_dien.CM_DM_TU_DIEN.Rows[v_i][CM_DM_TU_DIEN.ID])));
        }
    }
    #endregion
    #region Public Interfaces
    /// <summary>
    /// Hàm này ánh xạ tên thành viên dựa vào id_thanh_vien
    /// </summary>
    /// <param name="ip_obj_id_thanh_vien">ID_THANH_VIEN</param>
    /// <returns>Tên thành viên</returns>
    public string mapping_ten_thanh_vien_by_id(object ip_obj_id_thanh_vien)
    {
        US_DM_THANH_VIEN v_us_dm_thanh_vien = new US_DM_THANH_VIEN(CIPConvert.ToDecimal(ip_obj_id_thanh_vien));
        if (v_us_dm_thanh_vien.IsIDNull()) return "";
        return v_us_dm_thanh_vien.strTEN_THANH_VIEN;
    }
    #endregion

    protected void m_cbo_ten_du_an_SelectedIndexChanged(object sender, EventArgs e)
    {
        load_ten_thanh_vien_by_id_du_an_2_cbo_ten_thanh_vien();
        load_data_2_combo_cong_viec();
    }
}